using System.Threading.Tasks;
using JoyfulHomeJourney.BackEnd.Infrastructure.Dtos.Requests.Objects;
using JoyfulHomeJourney.BackEnd.Infrastructure.Dtos.Responses;
using JoyfulHomeJourney.BackEnd.Server.Interfaces;
using Microsoft.AspNetCore.Mvc;
namespace JoyfulHomeJourney.BackEnd.Api.Admin.Controllers
{
    public class SysCarShopsController : BaseController
    {
        private readonly ISysCarShopsServer _sysCarShopsServer;
        private readonly ISysCarServicesServer _sysCarServicesServer;
        private readonly ISysCarSuppliesServer _sysCarSuppliesServer;
        private readonly ISysVipPackagesServer _sysVipPackagesServer;

        public SysCarShopsController(ISysCarShopsServer sysCarShopsServer, ISysCarServicesServer sysCarServicesServer, ISysCarSuppliesServer sysCarSuppliesServer, ISysVipPackagesServer sysVipPackagesServer)
        {
            _sysCarShopsServer = sysCarShopsServer;
            _sysCarServicesServer = sysCarServicesServer;
            _sysCarSuppliesServer = sysCarSuppliesServer;
            _sysVipPackagesServer = sysVipPackagesServer;
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [TypeFilter(typeof(CheckLoginFilter), Arguments = new object[] { "admin" })]
        public async Task<IActionResult> Add([FromForm] RequestSysCarShopsDto dto)
        {
            return Send(await _sysCarShopsServer.AddAsync(dto));
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [TypeFilter(typeof(CheckLoginFilter), Arguments = new object[] { "admin" })]
        public async Task<IActionResult> Update(RequestSysCarShopsDto dto)
        {
            return Send(await _sysCarShopsServer.UpdateAsync(dto));
        }
        /// <summary>
        /// 详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [TypeFilter(typeof(CheckLoginFilter), Arguments = new object[] { "admin" })]
        public async Task<IActionResult> Detail(string id)
        {
            return Send(await _sysCarShopsServer.Detail(id));
        }
        /// <summary>
        /// 获取汽车店详情通过账号
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [TypeFilter(typeof(CheckLoginFilter), Arguments = new object[] { "carShop" })]
        public async Task<IActionResult> GetCarShopByAccount()
        {
            return Send(await _sysCarShopsServer.GetCarShopByAccount(_account.AId));
        }
        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        [HttpGet]
        [TypeFilter(typeof(CheckLoginFilter), Arguments = new object[] { "admin" })]
        public async Task<IActionResult> Pagination(int page, int limit, string key, string field, bool? order)
        {
            return Send(await _sysCarShopsServer.PaginationAsync(page, limit, key, field, order));
        }
        /// <summary>
        /// PC所有商品
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [TypeFilter(typeof(CheckLoginFilter), Arguments = new object[] { new string[] { "admin", "employee" } })]
        public async Task<IActionResult> pc_sys_products()
        {
            string uid = _account.AId;
            return Send(await _sysCarShopsServer.pc_sys_products(uid));
        }
        /// <summary>
        /// PC热门商品
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [TypeFilter(typeof(CheckLoginFilter), Arguments = new object[] { new string[] { "employee" } })]
        public async Task<IActionResult> pc_sys_productsrm()
        {
            string uid = _account.AId;
            return Send(await _sysCarShopsServer.pc_sys_productsrm(uid));
        }
        /// <summary>
        /// 产品分页根据汽车店编号
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="key"></param>
        /// <param name="shopId"></param>
        /// <param name="category"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> ProductPaginationByShopId(int page, int limit, string key, string shopId, string category)
        {
            switch (category)
            {
                case "car_services": return Send(await _sysCarServicesServer.PaginationAsync(page, limit, key, shopId, null, null));
                case "sys_car_supplies": return Send(await _sysCarSuppliesServer.PaginationAsync(page, limit, key, shopId, null, null));
                case "sys_vip_packages": return Send(await _sysVipPackagesServer.PaginationAsync(page, limit, key, shopId, null, null));
            }
            return Send(null);
        }
        /// <summary>
        /// 切换是否禁用
        /// </summary>
        /// <param name="shopId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> ToggleIsBan(string shopId)
        {
            return Send(await _sysCarShopsServer.ToggleIsBan(shopId));
        }
        /// <summary>
        /// 切换是否营业
        /// </summary>
        /// <param name="shopId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> ToggleIsOpen(string shopId)
        {
            return Send(await _sysCarShopsServer.ToggleIsOpen(shopId));
        }
        /// <summary>
        /// 获取当前汽车店的信息
        /// </summary>
        /// <param name="shopId"></param>
        /// <returns></returns>
        [HttpGet]
        [TypeFilter(typeof(CheckLoginFilter), Arguments = new object[] { "carShop" })]
        public async Task<IActionResult> Get_carshop()
        {
            var uid = _account.AId;
            return Send(await _sysCarShopsServer.Get_carshop(uid));
        }

        
    }
}
